package org.xg.study.boot.common.utils;

import org.xg.study.boot.common.ajax.ResultData;
import org.xg.study.boot.common.constant.ResponseCode;

import java.util.Date;

/**
 * @author CMG
 * @version 1.0
 * @cLassName ResultUtil
 * @description
 * @date 2021/8/25 16:47
 **/
public class ResultUtil {
    /**
     * @author cmg
     * @description //TODO 封裝成功返回結果
     * @date 2021/8/27 16:05
     * @param
     * @return org.xg.study.boot.common.ajax.ResultData<T>
     **/
    public static <T> ResultData<T> success(){
        ResultData<T> result = new ResultData<>();
        result.setRetCode(ResponseCode.SUCCESS.getRetCode());
        result.setRetMsg(ResponseCode.SUCCESS.getRetMsg());
        result.setRetInfo(ResponseCode.SUCCESS.getRetMsg());
        result.setDate(new Date());
        return result;
    }
    /**
     * @author cmg
     * @description //TODO 封裝成功返回結果
     * @date 2021/8/25 16:57
     * @param data
     * @return org.xg.study.boot.common.ajax.ResultData<T>
     **/
    public static <T> ResultData<T> success(T data){
        ResultData<T> result = new ResultData<>();
        result.setRetCode(ResponseCode.SUCCESS.getRetCode());
        result.setRetMsg(ResponseCode.SUCCESS.getRetMsg());
        result.setRetInfo(ResponseCode.SUCCESS.getRetMsg());
        result.setData(data);
        result.setDate(new Date());
        return result;
    }

    /**
     * @author cmg
     * @description //TODO 封裝成功返回結果
     * @date 2021/8/25 16:57
     * @param code
     * @param message
     * @return org.xg.study.boot.common.ajax.ResultData<T>
     **/
    public static <T> ResultData<T> success(int code, String message, String info){
        ResultData<T> result = new ResultData<>();
        result.setRetCode(code);
        result.setRetMsg(message);
        result.setRetInfo(info);
        result.setDate(new Date());
        return result;
    }

    /**
     * @author cmg
     * @description //TODO 封裝成功返回結果
     * @date 2021/8/25 16:58
     * @param data
     * @param code
     * @param message
     * @return org.xg.study.boot.common.ajax.ResultData<T>
     **/
    public static <T> ResultData<T> success(T data, int code, String message, String info){
        ResultData<T> result = new ResultData<>();
        result.setRetCode(code);
        result.setRetMsg(message);
        result.setRetInfo(info);
        result.setData(data);
        result.setDate(new Date());
        return result;
    }

    /**
     * @author cmg
     * @description //TODO 封裝失败返回結果
     * @date 2021/8/25 16:58
     * @param code
     * @param message
     * @return org.xg.study.boot.common.ajax.ResultData<T>
     **/
    public static <T> ResultData<T> fail(int code, String message, String info){
        ResultData<T> result = new ResultData<>();
        result.setRetCode(code);
        result.setRetMsg(message);
        result.setRetInfo(info);
        result.setDate(new Date());
        return result;
    }

    /**
     * @author cmg
     * @description //TODO 封裝失败返回結果-数据处理失败结果
     * @date 2021/8/25 16:58
     * @param message
     * @return org.xg.study.boot.common.ajax.ResultData<T>
     **/
    public static <T> ResultData<T> fail(String message){
        ResultData<T> result = new ResultData<>();
        result.setRetCode(ResponseCode.DATA_OPERATION_ERROR.getRetCode());
        result.setRetMsg(message);
        result.setRetInfo(message);
        result.setDate(new Date());
        return result;
    }

    /**
     * @author cmg
     * @description //TODO 封裝失败返回結果
     * @date 2021/8/25 16:59
     * @param data
     * @param code
     * @param message
     * @return org.xg.study.boot.common.ajax.ResultData<T>
     **/
    public static <T> ResultData<T> fail(T data, int code, String message, String info){
        ResultData<T> result = new ResultData<>();
        result.setRetCode(code);
        result.setRetMsg(message);
        result.setRetInfo(info);
        result.setData(data);
        result.setDate(new Date());
        return result;
    }
}
